from selenium.webdriver.common.by import By
from pages.base_page import Page


class AutoTranslationPage(Page):
    ele_title = (By.ID, u'page-autoTranslationConfig-title')
    ele_if_enable_auto_translation = (By.XPATH, u'//span[@data-tag="featureSwitch"]')
    ele_words_list = (By.ID, u'form-autoTranslationConfig-textarea-excludedWords')
    ele_save_button = (By.XPATH, u"//span[text()='Save']")

    # no feature
    ele_title_no_feature = (By.ID, u'autotranslation-title')
    ele_unlock_button = (By.XPATH, u"//span[text()='Unlock This Feature']/")

    ele_error = (By.XPATH, '//div[@role="alert"]')

    def __init__(self, driver, url, site_id):
        Page.__init__(self, driver, url)
        self.site_id = site_id
        self.url = url

    def check_is_enable_auto_translation(self):
        fs1 = self.find_element(*self.ele_if_enable_auto_translation)
        fs1.is_enabled()
        if fs1.text == 'OFF':
            self.click(self.ele_if_enable_auto_translation)
        else:
            pass

    def check_auto_translation_page_when_has_chat_translation_feature(self):
        self.find_element(*self.ele_title).is_enabled()
        self.input_text(self.ele_words_list, "Comm100")
        self.click(self.ele_save_button)

    def check_auto_translation_page_when_no_chat_translation_feature(self):
        self.find_element(*self.ele_title_no_feature).is_enabled()
        self.find_element(*self.ele_unlock_button).is_enabled()
